package org.developer.sentineldemo.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class demoController {

    @GetMapping("/demo")
    @SentinelResource(value = "demo",blockHandler = "exceptionHandler",fallback = "fallbackHandler")
    public String demo(String str) throws InterruptedException {
        return str;
    }

    public String exceptionHandler(String str,BlockException ex){
        return "访问过于频繁";
    }

    public String fallbackHandler(String str,BlockException ex){
        return "请求长时间无法响应";
    }
}
